# Author    : CoffeeChicken
# Date      : 2020-10-22 10:31
# Function  : 演示


from threading import Lock, Thread
import time

a = 0
lock1 = Lock()


def add1():
    global a
    for i in range(1, 10000001):
        lock1.acquire()
        a += 1
        lock1.release()
    print(f"add1运算的结果为:{a}")


def add2():
    global a
    for i in range(1, 10000001):
        lock1.acquire()
        a += 1
        lock1.release()
    print(f"add2运算的结果为:{a}")


if __name__ == '__main__':
    a1 = Thread(target=add1)
    a2 = Thread(target=add2)
    a1.start()
    a2.start()
    time.sleep(7)
    print(f"最终的结果为:{a}")
